import bean.ListNode;

public class Leetcode2095 {
    public static void main(String[] args) {
        Leetcode2095 leetcode2095 = new Leetcode2095();
//        System.out.println(leetcode2095.deleteMiddle(ListNode.createListNode(new int[]{1,3,4,7,1,2,6})));
        System.out.println(leetcode2095.deleteMiddle(ListNode.createListNode(new int[]{1,2,3,4, 5})));
    }

    public ListNode deleteMiddle(ListNode head) {


        if(head.next == null){
            return null;
        }

        ListNode n1 = head;
        ListNode n2 = head.next;
        ListNode n1Last = n1;

        while (n1.next != null && n2 != null && n2.next != null){
            n1Last = n1;
            n1 = n1.next;
            n2 = n2.next.next;
        }

//        n1.next = n1.next.next;

        if(n2 == null){
            n1Last.next = n1.next;
            return head;
        }

        if(n2.next == null){
            n1.next = n1.next.next;
            return head;
        }

        return head;
    }
}
